package com.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.reggie.dao.EmployeeDao;
import com.reggie.pojo.Employee;
import com.reggie.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    EmployeeDao dao;

    @Override
    public Employee login(Employee employee) {
        System.out.println(employee);
        LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Employee::getUsername, employee.getUsername()).eq(Employee::getPassword, employee.getPassword());
        Employee one = dao.selectOne(lqw);
        System.out.println(one);
        return one;
    }

    @Override
    public boolean addEmployee(Employee employee) {
        int flag = dao.insert(employee);
        return flag > 0;
    }

    @Override
    public boolean selectByUsername(String Username) {
        return dao.SelectByUsername(Username) != null;
    }

    @Override
    public List<Employee> selectByPage(Page page,LambdaQueryWrapper<Employee> lqw) {
        dao.selectPage(page, lqw);
        List<Employee> pageData = page.getRecords();
        return pageData;
    }

    @Override
    public Employee SelectById(Long id) {
        return dao.selectById(id);
    }

    @Override
    public boolean upDataStatus(Employee employee) {
        int i = dao.updateById(employee);
        return i > 0;
    }

    @Override
    public Employee selectById(Long id) {
        return dao.selectById(id);
    }

    @Override
    public Boolean updateEmployee(Employee employee) {
        LambdaQueryWrapper<Employee> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Employee::getId,employee.getId());
        return dao.update(employee,lqw)>0;
    }
}
